package com.example.springboot01.controller;

import com.example.springboot01.entity.Teacher;
import com.example.springboot01.req.PageQueryReq;
import com.example.springboot01.resp.Response;
import com.example.springboot01.service.TeacherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @PostMapping
    public Response save(@RequestBody Teacher teacher) {
        teacherService.addTeacher(teacher);
        return Response.ok(null);
    }

    @PutMapping
    public Response update(@RequestBody Teacher teacher) {
        teacherService.updateById(teacher);
        return Response.ok(null);
    }


    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Integer id) {
        teacherService.removeById(id);
        return Response.ok(null).setMsg("删除成功");
    }

    @GetMapping
    public Response list() {
        return Response.ok(teacherService.list());
    }


    @GetMapping("/page")
    public Response page(PageQueryReq req) {
        return Response.ok(teacherService.getPage(req));
    }

    @GetMapping("/students")
    public Response listStudent() {
        return Response.ok(teacherService.listStudent());
    }


    @GetMapping("/getCourse")
    public Response getCourse() {
        return Response.ok(teacherService.getCourse());
    }
}
